package com.syni.mdd.sjb.common.datatreaure.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.syni.mdd.sjb.common.component.mybatis.dxshapp.entity.DxshAppBanner;
import com.syni.mdd.sjb.common.component.mybatis.dxshapp.mapper.DxshAppBannerMapper;
import com.syni.mdd.sjb.common.component.utils.common.utils.BeanUtils;
import com.syni.mdd.sjb.common.component.utils.common.utils.ResultMapHelper;
import com.syni.mdd.sjb.common.datatreaure.service.DxshAppBannerService;
import com.syni.mdd.sjb.common.datatreaure.constants.Constants;
import com.syni.mdd.sjb.common.datatreaure.constants.ResultMsg;
import com.syni.mdd.sjb.common.datatreaure.entity.vo.rp.service.BannerRpVo;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lcc
 * @since 2020-04-26
 */
@Service
public class DxshAppBannerServiceImpl extends ServiceImpl<DxshAppBannerMapper, DxshAppBanner> implements DxshAppBannerService {
    String indexImg = "http://dsp-1251624226.cos.ap-guangzhou.myqcloud.com/business/b20200608233414395E92y.png";
    String allImg = "http://dsp-1251624226.cos.ap-guangzhou.myqcloud.com/business/b20200608233506352579E.png";
    String minImg = "http://dsp-1251624226.cos.ap-guangzhou.myqcloud.com/business/b202006082335324919SK3.png";
    String mddImg = "http://dsp-1251624226.cos.ap-guangzhou.myqcloud.com/business/b20200608233606502DV2D.png";

    @Override
    public Map<String, Object> getBanner() {
        List<BannerRpVo> bannerRpVoList = bannerList(type);
        return ResultMapHelper.success(bannerRpVoList, ResultMsg.MSG_GET_SUCCESS);
    }

    @Override
    public List<BannerRpVo> bannerList(Integer type) {
        List<DxshAppBanner> dxshAppBannerList = this.list(new QueryWrapper<DxshAppBanner>().eq(DxshAppBanner.TYPE,type)
                .orderByAsc(DxshAppBanner.BANNER_INDEX).eq(DxshAppBanner.IS_OFF,Constants.COMMON_FLAG_FALSE_INT));
        if(CollectionUtils.isEmpty(dxshAppBannerList)){
            DxshAppBanner dxshAppBanner = new DxshAppBanner();
            switch (type){
                case DxshAppBannerService.type:
                    dxshAppBanner.setBannerIndex(1);
                    dxshAppBanner.setImgUrl(indexImg);
                    break;
                case DxshAppBannerService.CHANNEL_ALL_TYPE :
                    dxshAppBanner.setBannerIndex(1);
                    dxshAppBanner.setImgUrl(allImg);
                    break;
                case DxshAppBannerService.CHANNEL_MDD_TYPE:
                    dxshAppBanner.setBannerIndex(1);
                    dxshAppBanner.setImgUrl(mddImg);
                    break;
                case DxshAppBannerService.CHANNEL_MIN_TYPE:
                    dxshAppBanner.setBannerIndex(1);
                    dxshAppBanner.setImgUrl(minImg);
                    break;
                default:break;
            }
            dxshAppBannerList.add(dxshAppBanner);
        }
        List<BannerRpVo> bannerRpVoList = BeanUtils.copyList(dxshAppBannerList,BannerRpVo.class);
        return bannerRpVoList;
    }


    @Override
    public List<DxshAppBanner> getIndexBanner() {
        QueryWrapper queryWrapper = new QueryWrapper<DxshAppBanner>().
                eq(DxshAppBanner.TYPE,INDEX_TYPE).
                eq(DxshAppBanner.IS_OFF, Constants.COMMON_FLAG_FALSE_INT).
                orderByDesc(DxshAppBanner.NEW_TIME);
        return this.list(queryWrapper);
    }


}
